<template>
    <view class="container">
        <image class="bg-image" src="/static/image.jpg" mode="aspectFill"></image>
        <view class="nav-bar">
            <view class="back-btn" @click="goBack">
                <image src="/static/return.png" mode="aspectFit" class="back-icon"/>
            </view>
            <text class="nav-title">上传文章</text>
        </view>
        
        <view class="content">
            <view class="card-body">
                <view class="input-group">
                    <input 
                        class="title-input"
                        v-model="article.title"
                        placeholder="请输入文章标题"
                        placeholder-class="placeholder"
                    />
                    <textarea 
                        class="content-input"
                        v-model="article.content"
                        placeholder="请输入文章内容"
                        placeholder-class="placeholder"
                    />
                </view>
                <button class="submit-btn" @click="submitArticle">提交文章</button>
            </view>
        </view>
    </view>
</template>

<script>
import { add_article } from '@/api/user.js'

export default {
    data() {
        return {
            article: {
                title: '',
                content: ''
            }
        }
    },
    methods: {
        goBack() {
            uni.navigateBack()
        },
        async submitArticle() {
            if (!this.article.title || !this.article.content) {
                uni.showToast({
                    title: '请填写完整信息',
                    icon: 'none'
                })
                return
            }
            
            try {
                const res = await add_article({
                    article_title: this.article.title,
                    article_content: this.article.content
                })
                
                if (res.code === '2000') {
                    uni.showToast({
                        title: '上传成功',
                        icon: 'success'
                    })
                    setTimeout(() => {
                        uni.navigateBack()
                    }, 1500)
                } else {
                    uni.showToast({
                        title: res.message || '上传失败',
                        icon: 'none'
                    })
                }
            } catch (error) {
                console.error('上传文章失败：', error)
                uni.showToast({
                    title: '上传失败',
                    icon: 'none'
                })
            }
        }
    }
}
</script>

<style>
.container {
    position: relative;
    min-height: 100vh;
}

.bg-image {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: -1;
}

.nav-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    padding: 40px 20px 20px;
    z-index: 100;
}

.back-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-icon {
    width: 24px;
    height: 24px;
}

.nav-title {
    flex: 1;
    text-align: center;
    font-size: 18px;
    font-weight: 500;
    color: #333;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5);
}

.content {
    padding: 100px 20px 20px;
    min-height: 100vh;
}

.card-body {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 20px;
}

.input-group {
    margin-bottom: 20px;
}

.title-input {
    width: 100%;
    height: 44px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 0 15px;
    margin-bottom: 15px;
    font-size: 16px;
}

.content-input {
    width: 100%;
    height: 200px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 15px;
    font-size: 16px;
}

.placeholder {
    color: rgba(102, 102, 102, 0.6);
}

.submit-btn {
    background: rgba(107, 75, 138, 0.9);
    color: #fff;
    height: 44px;
    line-height: 44px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
}

.submit-btn:active {
    opacity: 0.8;
}
</style> 